package com.cmwa.scbp.sys.msg.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import com.cmwa.scbp.sys.msg.dao.IEmailParameterDao;
import com.cmwa.scbp.sys.msg.service.IEmailParameterService;
import com.cmwa.scbp.sys.msg.vo.EmailParameterVo;
import com.cmwa.scbp.utils.spring.SpringContextUtil;

@Service
@SuppressWarnings("rawtypes")
public class EmailParameterServiceImpl implements IEmailParameterService{
	@Resource
	private IEmailParameterDao emailParameterDao;

	private String mailConf;
	
	@Override
	public EmailParameterVo getEmailParameter() {
		String _mailConf = "CMMAILCONF";
		if(mailConf != null){
			_mailConf = SpringContextUtil.getBean(Environment.class).getProperty("sys." + mailConf);
		}
		EmailParameterVo vo = new EmailParameterVo();
		List<Map> tmp=emailParameterDao.getEmailParameter(_mailConf);
		for(Map m : tmp){
			
			String key = m.get("PMCD").toString();
			String value = m.get("PMVL").toString();
			
			if("SERVER".equals(key)) {
				vo.setServer(value);
			} else if("USER".equals(key)) {
				vo.setUser(value);
			} else if("ADDRESS".equals(key)) {
				vo.setAddress(value);
			} else if("PASSWORD".equals(key)) {
				vo.setPassword(value);
			}
		}
		return vo;
	}

	public void setEmailParameterDao(IEmailParameterDao emailParameterDao) {
		this.emailParameterDao = emailParameterDao;
	}
	
	public void setMailConf(String mailConf){
		this.mailConf = mailConf;
	}

}
